//
//  UMengVerifySupport.m
//  Runner
//
//  Created by Yunxi on 2021/8/27.
//

#import "UMengVerifySupport.h"
#import <Flutter/Flutter.h>
#import <UMVerify/UMCustomModel.h>
#import <UMVerifyHandler.h>
#import "VerifyLoginBackView.h"
#import "DeviceConfig.h"
#import "UIImage+Gradient.h"
#import <UmengVertifyPlugin.h>

@implementation UMengVerifySupport

+ (void)createUMengVerifyViewModel{
    NSLog(@"注册友盟验证model通知");
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    
    FlutterMethodChannel *channel = [FlutterMethodChannel methodChannelWithName:@"yyt.verify.model" binaryMessenger:window.rootViewController];
    [channel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {
        NSLog(@"接收到设置model的消息");
        if ([call.method isEqualToString:@"configVerifyPageModel"]){
            [UMVerifyHandler modelConfigWithModel:[UMengVerifySupport getCustomModel]];
        }
    }];
}


+ (UMCustomModel *)getCustomModel {
    UMCustomModel *model = [UMCustomModel new];
    
    //导航栏
    model.navIsHidden = YES;
    
//    model.navColor = [UIColor clearColor];
//    model.navTitle = [[NSAttributedString alloc] initWithString:@""];
//    NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"ATAuthSDK" ofType:@"bundle"]];
    
//    model.navBackImage = [UIImage imageNamed:[bundle pathForResource:@"icon_close_gray@2x" ofType:@"png"]];
    //logo
    model.logoImage = [UIImage imageNamed:@"slogan"];
    model.logoFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {

//        frame.origin.y = 146*ScaleW;
        frame.origin.y = 112*ScaleH;
        frame.origin.x = 0;
        frame.size.width = ScreenWidth;
        return frame;
    };
    
    //slogan
//    model.sloganText = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:209.0/255 green:209.0/255 blue:212.0/255 alpha:1],NSFontAttributeName:[UIFont systemFontOfSize:12.0]}];
    model.sloganFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
//        frame.origin.y = 428*ScaleW;
        frame.origin.y = 318*ScaleH;

        return  frame;
    };
    
    //手机号
    model.numberFont = [UIFont boldSystemFontOfSize:28];
    model.numberColor = [UIColor whiteColor];
    model.numberFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
//        frame.origin.y = 386*ScaleW;
        frame.origin.y = 276*ScaleH;

        return frame;
    };
    
    //一键登录按钮
    model.loginBtnText =[[NSAttributedString alloc] initWithString:@"一键登录" attributes:@{NSForegroundColorAttributeName:UIColor.whiteColor,NSFontAttributeName:[UIFont systemFontOfSize:17.0]}];
    model.loginBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
//        frame.origin.y = 484*ScaleW;
        frame.origin.y = 374*ScaleH;

        return frame;
    };
    UIImage *gradientImage = [UIImage gradientColorImageFromColors:@[
        [UIColor colorWithRed:255.0/255 green:34.0/255 blue:66.0/255 alpha:1],
        [UIColor colorWithRed:255.0/255 green:116.0/255 blue:136.0/255 alpha:1]]
                                                      gradientType:GradientTypeLeftToRight
                                                           imgSize:CGSizeMake(ScreenWidth-60*ScaleW, 50)];
    UIImage *bgImage = [UIImage setCornerWithImage:gradientImage cornerRadius:10.0];
    model.loginBtnBgImgs = @[bgImage,bgImage,bgImage];
    
    //随便逛逛
    model.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"随便逛逛" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:255.0/255 green:255.0/255 blue:255.0/255 alpha:0.6],NSFontAttributeName:[UIFont systemFontOfSize:14.0]}];
    model.changeBtnFrameBlock = ^CGRect(CGSize screenSize, CGSize superViewSize, CGRect frame) {
//        frame.origin.y = 564*ScaleW;
        frame.origin.y = 440*ScaleH;
    
        return frame;
    };
    BOOL isCloseShow = [UmengVertifyPlugin getCloseButtonIsShow];
    if (isCloseShow) {
        model.changeBtnIsHidden = YES;
        model.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:255.0/255 green:255.0/255 blue:255.0/255 alpha:0.6],NSFontAttributeName:[UIFont systemFontOfSize:14.0]}];
    }else {
        model.changeBtnIsHidden = NO;
        model.changeBtnTitle = [[NSAttributedString alloc] initWithString:@"随便逛逛" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:255.0/255 green:255.0/255 blue:255.0/255 alpha:0.6],NSFontAttributeName:[UIFont systemFontOfSize:14.0]}];
    }

    //协议
    model.privacyOne = @[@"《用户服务协议》",@"http://http://yytjs.cn/userserviceagreement.html"];
    model.privacyTwo = @[@"《隐私政策》",@"http://yytjs.cn/privacyagreement.html"];
    model.privacyColors = @[UIColor.whiteColor, UIColor.whiteColor];
    model.privacyOperatorPreText = @"《";
    model.privacyOperatorSufText = @"》";
    model.privacyFont = [UIFont systemFontOfSize:12];

    //自定义view
    model.customViewBlock = ^(UIView * _Nonnull superCustomView) {
        [superCustomView addSubview:[VerifyLoginBackView new]];
    };
    
    return model;
}

@end
